package com.jf.cloud.im.controller.platform;

import com.jf.cloud.common.constant.Constant;
import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.im.dto.ImMsgBizSkillsDTO;
import com.jf.cloud.im.service.ImMsgBizSkillsService;
import com.jf.cloud.im.vo.ImMsgBizSkillsVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import ma.glasnost.orika.MapperFacade;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 客服自动回复表
 *
 * @author zz
 * @date 2023-03-23 17:43:40
 */
@RestController("platformImMsgBizSkillsController")
@RequestMapping("/p/im_msg_biz_skills")
@Tag(name = "平台自动回复接口")
public class ImMsgBizSkillsController {

    @Autowired
    private ImMsgBizSkillsService imMsgBizSkillsService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取客服自动回复表列表", description = "分页获取客服自动回复表列表")
    public ServerResponseEntity<PageVO<ImMsgBizSkillsVO>> page(@Valid PageDTO pageDTO, @ParameterObject ImMsgBizSkillsDTO imMsgBizSkillsDTO) {
        Long shopId = Constant.PLATFORM_SHOP_ID;
        PageVO<ImMsgBizSkillsVO> imMsgBizSkillsPage = imMsgBizSkillsService.page(pageDTO, imMsgBizSkillsDTO, shopId);
        return ServerResponseEntity.success(imMsgBizSkillsPage);
    }

    @GetMapping
    @Operation(summary = "获取客服自动回复表", description = "根据id获取客服自动回复表")
    public ServerResponseEntity<ImMsgBizSkillsVO> getById(@RequestParam Long id) {
        return ServerResponseEntity.success(imMsgBizSkillsService.getById(id));
    }

    @PostMapping
    @Operation(summary = "保存客服自动回复表", description = "保存客服自动回复表")
    public ServerResponseEntity<Void> save(@Valid @RequestBody ImMsgBizSkillsDTO imMsgBizSkillsDTO) {
        ImMsgBizSkillsVO imMsgBizSkills = mapperFacade.map(imMsgBizSkillsDTO, ImMsgBizSkillsVO.class);
        imMsgBizSkills.setShopId(Constant.PLATFORM_SHOP_ID);
        imMsgBizSkillsService.save(imMsgBizSkills);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新客服自动回复表", description = "更新客服自动回复表")
    public ServerResponseEntity<Void> update(@Valid @RequestBody ImMsgBizSkillsDTO imMsgBizSkillsDTO) {
        ImMsgBizSkillsVO imMsgBizSkills = mapperFacade.map(imMsgBizSkillsDTO, ImMsgBizSkillsVO.class);
        imMsgBizSkillsService.update(imMsgBizSkills);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除客服自动回复表", description = "根据客服自动回复表id删除客服自动回复表")
    public ServerResponseEntity<Void> delete(@RequestParam Long id) {
        imMsgBizSkillsService.deleteById(id);
        return ServerResponseEntity.success();
    }
}